{% extends base.html %}

{% block body %}
<div class="col-md-12">
    <a href="/system/script" class="tab-link">脚本</a>
    <a href="/system/crontab" class="tab-link">定时任务</a>
</div>

<div class="col-md-12">
    <input class="dialog-btn" type="button" value="添加" dialog-url="/system/crontab/edit" />
</div>

<div class="col-md-12 top-offset-1">
<table class="table col-md-12">
    <tr>
        <th>编号</th>
        <th>任务</th>
        <th>时间</th>
        <th>操作</th>
    </tr>
    {% set index = -1 %}
    {% for index, task in enumerate(task_list) %}
    {% set name = task.url %}
    <tr class="hover-tr">
        <td class="row-no">{{index+1}}</td>
        <td>
            <div style="word-wrap: break-word;">
                {% if task.protocol == "script" %}
                    <a href="/system/script_admin/edit?name={{task.script_name}}">{{task.script_name}}</a>
                {% else %}
                    {{task.display_name}}
                {% end %}
            </div>
        </td>
        <td>{{xutils.wday_map[task.tm_wday]}} 
            {% if task.tm_hour == "*" %} 每小时 {% else %} {{task.tm_hour}}时 {% end %}
            {% if task.tm_min == "*" %} 每分钟 {% else %} {{task.tm_min}}分 {% end %} 
        </td>
        <td>
            {% if task.id %}
            <input class="dialog-btn" type="button" value="编辑" 
                dialog-url="/system/crontab/edit?id={{task.id}}" 
                href="/system/crontab/edit?id={{task.id}}" />
            <input type="button" class="link-btn btn-danger" value="删除" href="/system/crontab/remove?id={{task.id}}" confirm-message="确认删除 {{task.display_name}} ?">
            {% end %}
        </td>
    </tr>
    {% end %}
</table>
</div>

<script type="text/javascript">
    $("#url_type").on("change", function (event) {
        console.log(event);
        var target = event.target;
        var value = $(target).val();
        if (value == "script") {
            $("select[name=script_url]").show();
            $("input[name=url]").val("").hide();
        } else {
            $("input[name=url]").show();
            $("select[name=script_url]").val("").hide();
        }
    })
</script>
{% end %}